import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

typedef OnItemSelectedCallback = void Function(int index);

// ignore: must_be_immutable
class HomeBottom extends StatefulWidget {
  final int length;
  final icons;
  final array;
  final selectedIcons;
  var textColor = Colors.grey[500];
  var textSelectedColor = Colors.grey[500];
  var currentItem = 0;
  final height;
  final OnItemSelectedCallback onItemSelectedCallback;

  HomeBottom({
    this.height,
    this.length,
    this.icons,
    this.array,
    this.selectedIcons,
    this.textColor,
    this.textSelectedColor,
    this.currentItem,
    this.onItemSelectedCallback,
  });

  @override
  State<StatefulWidget> createState() {
    return _HomeBottom();
  }
}

class _HomeBottom extends State<HomeBottom> {
  var co = [Colors.white, Colors.white, Colors.white];

  @override
  Widget build(BuildContext context) {
    return Row(
      children: List.generate(widget.length, (index) {
        return Expanded(
          child: Material(
            child: Ink(
              decoration:
                  BoxDecoration(borderRadius: BorderRadius.circular(10)),
              child: InkWell(
                onTapDown: (detail){
                  print("xxx");
                  if (null != widget.onItemSelectedCallback) {
                    widget.onItemSelectedCallback(index);
                  }
                },
                onTap: () {
                  print("onTapDown");

                },
                child: Container(
                  width: double.infinity,
                  height: widget.height ?? 50,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      SizedBox(
                        height: 25,
                        child: Image.asset(
                          widget.currentItem == index
                              ? widget.selectedIcons[index]
                              : widget.icons[index],
                          fit: BoxFit.cover,
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.only(top: 5),
                        child: Text(
                          widget.array[index],
                          style: TextStyle(
                              color: isCurrent(index)
                                  ? widget.textSelectedColor
                                  : widget.textColor,
                              fontSize: 11),
                        ),
                      )
                    ],
                  ),
                ),
              ),
            ),
          ),
        );
      }),
    );
  }

  bool isCurrent(int index) {
    return widget.currentItem == index;
  }
}
